package com.jic.market.impl;
import	java.util.Date;

import java.lang.Long;
import java.util.List;
import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.market.entity.PromotionBargain;
import com.jic.market.mapper.PromotionBargainMapper;
import com.jic.market.service.PromotionBargainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 砍价活动表
 * @author : 
 * @email : 
 * @since : 2020-09-10 06:18:49
 * @version : v1.0.0
 */
@Service
public class PromotionBargainServiceImpl implements PromotionBargainService {

    @Autowired
    private PromotionBargainMapper promotionBargainMapper;

    @Override
    public long insert(PromotionBargain promotionBargain) {
        long flag = promotionBargainMapper.insert(promotionBargain);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return promotionBargainMapper.delete(id);
    }

    @Override
    public long update(PromotionBargain promotionBargain) {
        return promotionBargainMapper.update(promotionBargain);
    }

    @Override
    public PromotionBargain queryByPrimaryKey(Long id){
        return promotionBargainMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<PromotionBargain> query(PromotionBargain promotionBargain){
        return promotionBargainMapper.query(promotionBargain);
    }

    @Override
    public PageResult<PromotionBargain> queryPage(PromotionBargain promotionBargain, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<PromotionBargain> list = promotionBargainMapper.queryPage(startIndex, pageQuery.getLimit(), promotionBargain);
        long count = promotionBargainMapper.queryPageCount(promotionBargain);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }

    @Override
    public RestResult insertPromotion(PromotionBargain promotionBargain) {
        RestResult result = new RestResult();
        promotionBargain.setCreateTime(new Date());
        promotionBargain.setDeptId(0L);
        if (null != promotionBargain.getId()){
            promotionBargainMapper.update(promotionBargain);
        }else {
            promotionBargainMapper.insert(promotionBargain);
        }
        result.setCode("0000");
        result.setData(promotionBargain.getId());
        return result;
    }
}